cmake_minimum_required(VERSION 3.15)

# Find PostgreSQL (libpq)
find_package(PostgreSQL REQUIRED)
find_package(Threads REQUIRED)

# ingestd server executable
add_executable(ingestd
  src/server.cpp
  src/handler.cpp
  src/stream_handler.cpp  # NEW: High-performance stream handler
  src/sql_writer_pq.cpp
  src/query_handler.cpp
  src/ilp_handler.cpp
)

target_link_libraries(ingestd
  PRIVATE
    ingest_proto
    PostgreSQL::PostgreSQL
    Threads::Threads
)

target_include_directories(ingestd PRIVATE
  ${CMAKE_SOURCE_DIR}/generated
  ${CMAKE_SOURCE_DIR}/proto
  ${CMAKE_CURRENT_SOURCE_DIR}/src
)

# C++17 required
target_compile_features(ingestd PRIVATE cxx_std_17)